package com.hospital.controller;


import com.hospital.domain.Register;
import com.hospital.service.RegisterService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.sql.Date;
import java.util.List;

@RestController
@RequestMapping("/register")
public class RegisterController {


    @Autowired
    RegisterService registerService;

    @PostMapping("/addRegis")
    public int addRegister(@RequestBody Register register,HttpSession session){
//        System.out.println(register);
        int userID = (int)session.getAttribute("userID");
        register.setUserID(userID);
        return registerService.addRegister(register);
    }

    @GetMapping("/selectRegis")
    public List<Register> selectRegis(HttpSession session){
        int userID = (int)session.getAttribute("userID");
        List<Register> registers = registerService.selectRegisterByUserID(userID);
        System.out.println(registers);
        return registers;
    }

    @GetMapping("deleteById")
    public int deleteById(int id){
        return registerService.deleteResById(id);
    }

    @PostMapping("selectDoctorID")
    public List<Register> selectRegisterDoctorID(@RequestBody Register register,HttpSession session){
        System.out.println(register);
        int doctorID = register.getDoctorID();
        Date date = register.getDate();
        String userName = register.getUserName();
        String amorPM = register.getAmorPM();
        return registerService.selectRegisterByDoctorID(doctorID,date,userName,amorPM);
    }

    @PostMapping("/timesOrder")
    public int selectTimesOrder(@RequestBody Register register,HttpSession session){
        int userID = (int)session.getAttribute("userID");
        register.setUserID(userID);
        return registerService.selectTimesOrder(register);
    }

    @GetMapping("updateInfor")
    public int updatainfor(@RequestParam("remarks") String remarks,@Param("registID") int registID){
        return registerService.addinfor(remarks,registID);
    }
}
